<% /* $Id: monitor.jsp 132 2011-08-26 10:23:42Z altdotua@gmail.com $ */ %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ include file="header.jsp" %>

<%

	if (user == null)
	{
		response.sendRedirect(Linker.link("login.jsp?return=" + URLEncoder.encode(request.getRequestURI().substring(1), "UTF-8")));
		return;
	}
	// rowcolor
	String rowColor = request.getParameter("rowcolor") != null ? request.getParameter("rowcolor") : "none";
	// cellcolor
	String cellColor = request.getParameter("cellcolor") != null ? request.getParameter("cellcolor") : "true";
	
	List<ContestUserScoreEntry> userScoreEntries = ContestUserScoreModel.getContestEntries(contest.getId());
	Collections.sort(userScoreEntries, new ACMComparator());
	List<ContestProblemEntry> problemEntries = ContestProblemsModel.getContestEntries(contest.getId().toString());
	Map<Long, UserEntry> userEntriesMap = UsersModel.getEntriesMap();
	Map<Long, ContestProblemScoreEntry> problemScores = ContestProblemScoreModel.getContestProblemEntries(contest.getId());
	ContestScoreEntry contestScoreEntry = ContestScoreModel.getContestEntry(contest.getId());
%>


<table>
	<tr>
		<th>Місце</th>
		<th>Учасник</th>
		<th>Задачі</th>
		<th>Спроби</th>
	</tr>
<%
	int c = 0, last_score = -1, last_place = 0;
	long last_time = -1;
	for (ContestUserScoreEntry userScoreEntry: userScoreEntries)
	{
		c++;
		if (userScoreEntry.getUniqueAcceptedCount() != last_score || userScoreEntry.getTotalTimePen() != last_time)
			last_place = c;
		last_score = userScoreEntry.getAcceptedCount();
		last_time = userScoreEntry.getTotalTimePen();
		
		UserEntry userEntry = userEntriesMap.get(userScoreEntry.getUserId());
%>
<tr>
	<td><%= last_place %></td>
	<td><%= StringEscapeUtils.escapeHtml(userEntry.getUsername())  %></td>
	<td><%= userScoreEntry.getUniqueAcceptedCount()  %></td>
	<td><%= userScoreEntry.getUniqueAcceptedCount() + userScoreEntry.getUniqueRejectedCount()  %></td>
</tr>
<%
	}
%>
</table>




<%
	Long pageGenerationFinished = new Date().getTime();
%>

<!-- <%= "" + ((pageGenerationFinished - pageGenerationStarted)) + " ms" %>  -->


<%@ include file="footer.jsp" %>